$(document).ready(function () {
	initMessage();
})

function initMessage() {

	$.ajax({
		type: 'get',
		url: '/api/message',
		dataType:"json",
		data:{
			"pageSize":20,
			"pageNumber":0
		},
		success: function (result) {
			var data = result.data;
			$("#message_list").html("")
			$("#message_account").html(result.totalCount)
			var val = "";
			data.forEach(function(value,index){

				val = val+ "<tr>" +
							"<td>"+value.nickname+"</td>" +
							"<td>"+value.context+"</td>" +
							"<td>"+value.createTime+"</td>" +
							"<td>" +
							"<a role=\"button\" class=\"btn_open\" style=\"border: 1px solid #eee;padding: 2px 4px;margin: 0px 4px;\">" +
							"<span class='glyphicon glyphicon-eye-open'></span>" +
							"已显示" +
							"</a>" +
							"<a role=\"button\" class=\"btn_auditions\"\n" +
							"style=\"border: 1px solid #09BB07;padding: 2px 4px;margin: 0px 4px;\">" +
							"<span class='glyphicon glyphicon-eye-open'></span>" +
							"查看" +
							"</a>" +
							"<a role=\"button\" class=\"btn_delete\"\n" +
							"style=\"border: 1px solid #e7505a;padding: 2px 4px;margin: 0px 4px;\">" +
							"<span class='glyphicon glyphicon-trash'></span>" +
							"删除" +
							"</a>" +
							"</td>" +
							"</tr>"


			});
			$("#message_list").append(val)
		},
		error:function () {
			layer.msg("系统错误！",{icon: 5});
		}
	});
}


$(".btn_b").click(function(){
	$(".message_reply").css({
		"display":"none",
	});
})
$(".message_btn").click(function(){
	$(".message_reply").css({
		"display":"none",
	});
})


/*
function querylinkById(id) {
	$.ajax({
		url:"/api/querylinkById/"+id,
		type:"get",
		dataType:"json",
		success:function(result){
			$(".xg_id").val(result.data.id);
			$(".xg_name").val(result.data.title);
			$(".xg_con").val(result.data.synopsis);
			$(".xg_logo").val(result.data.icon);
			$(".xg_url").val(result.data.url);
		},
		error:function () {
			layer.msg("系统错误！",{icon: 5});
		}
	});
}

function deleteLink(id) {
	$.ajax({
		url:"/api/deleteLink/"+id,
		type:"get",
		dataType:"json",
		success:function(result){
			initLink();
		},
		error:function () {
			layer.msg("系统错误！",{icon: 5});
		}
	});
}



$(function(){

	//通过append添加的HTML事件无效,使用on方法
	$(document).on("click", ".btn_edit", function () {
		$(".link_div").css({
			"display":"block",
		});
	});

	/!*$(".btn_edit").click(function(){
		$(".link_div").css({
			"display":"block",
		});
	})*!/

	$(".btn_qx").click(function(){
		$(".link_div").css({
			"display":"none",
		});
	})

	$(".btn_xg").click(function(){

		$.ajax({
			type: 'POST',
			url: '/api/updatelink',
			dataType:"json",
			data: {
				'id':  $(".xg_id").val(),
				'title': $(".xg_name").val(),
				'synopsis': $(".xg_con").val(),
				'icon':$(".xg_logo").val(),
				'url':$(".xg_url").val()
			},
			success: function (result) {
				if (result.code==200){
					layer.msg(result.message,{icon: 1});
					window.setTimeout(function () {
						window.location.href="/admin/link"
					},1000)
				} else {
					layer.msg(result.message,{icon: 5});
				}

			},
			error:function () {
				layer.msg("系统错误！",{icon: 5});
			}
		});
	})



})
*/






$(function(){

	//通过append添加的HTML事件无效,使用on方法
	$(document).on("click", ".btn_edit", function () {
		$(".message_btn").css({
			"display":"none",
		});
	});
	$(document).on("click", ".btn_auditions", function () {
		$(".message_reply").css({
			"display":"block",
		});
	});
	
	/*$(".btn_auditions").click(function(){
		$(".message_reply").css({
			"display":"block",
		});
	})
	
	$(".message_btn").click(function(){
		$(".message_reply").css({
			"display":"none",
		});
	})*/
	
})
